<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - May 19, 2013
 */
require 'foo.config.php';

if (isset($_POST['serialno'])) {
    if ($_REQUEST['action'] == 'AddStockIn') {
        $query = "INSERT INTO stockin ( serialno, project_id, productid, description, revisionstate, uom, in_quantity, shiptype, 
                    invoicenumber, shipid, mawb, hawb, receiveddate, shipfrom, boxno, rma, warehouse_id, rackno, docketnumber, 
                    manufacturingdate, pickuprequestdate, employee_id, eng_id, siteid, docketdate, remarks, userid, cus_id, session_id, junkentry, inserteddate )

            VALUES ( :serialno, :project_id, :productid, :description, :revisionstate, :uom, :in_quantity, :shiptype,
                    :invoicenumber, :shipid, :mawb, :hawb, :receiveddate, :shipfrom, :boxno, :rma, :warehouse_id, :rackno, :docketnumber, 
                    :manufacturingdate, :pickuprequestdate, :employee_id, :eng_id, :siteid, :docketdate, :remarks, :userid, :cus_id, :session_id, :junkentry, :inserteddate)";

        $query_params = array(
            ':serialno' => $_POST['serialno'],
            ':productid' => $_POST['productid'],
            ':description' => $_POST['description'],
            ':revisionstate' => $_POST['revisionstate'],
            ':uom' => $_POST['uom'],
            ':in_quantity' => $_POST['in_quantity'],
            ':shiptype' => $_POST['shiptype'],
            ':warehouse_id' => $_POST['warehouse_id'],
            ':rackno' => $_POST['rackno'],
            ':invoicenumber' => $_POST['invoicenumber'],
            ':shipid' => $_POST['shipid'],
            ':mawb' => $_POST['mawb'],
            ':hawb' => $_POST['hawb'],
            ':receiveddate' => $_POST['receiveddate'],
            ':rma' => $_POST['rma'],
            ':shipfrom' => $_POST['shipfrom'],
            ':docketnumber' => $_POST['docketnumber'],
            ':manufacturingdate' => $_POST['manufacturingdate'],
            ':pickuprequestdate' => $_POST['pickuprequestdate'],
            ':employee_id' => $_POST['employee_id'],
            ':eng_id' => $_POST['eng_id'],
            ':siteid' => $_POST['siteid'],
            ':docketdate' => $_POST['docketdate'],
            ':boxno' => $_POST['boxno'],
            ':serialno' => $_POST['serialno'],
            ':project_id' => $_POST['project_id'],
            ':remarks' => $_POST['remarks'],
            ':userid' => $_POST['userid'],
            ':cus_id' => $_POST['cus_id'],
            ':session_id' => $_POST['session_id'],
            ':junkentry' => $_POST['junkentry'],
            ':inserteddate' => date('Y-m-d H:i:s')
        );
        //var_dump($query_params);
        try {
            $stmt = $db->prepare($query);
            $result = $stmt->execute($query_params);
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }

        if ($result) {
            $session_id = session_id();
            $rows = selectAllWhereAA('stockin', 'session_id', $session_id, $db);

            echo "<table class=\"row-fluid table table-striped table-bordered\">";
            echo "<tr>";
            echo "<th>" . $optionsIcons['optionIcon'] . "</th>";
            echo "<th>" . $stock_in['serialno'] . "</th>";
            echo "<th>" . $stock_in['project_id'] . "</th>";
            echo "<th>" . $stock_in['productid'] . "</th>";
            echo "<th>" . $stock_in['description'] . "</th>";
            echo "<th>" . $stock_in['revisionstate'] . "</th>";
            echo "<th>" . $stock_in['shiptype'] . "</th>";
            echo "<th>" . $stock_in['in_quantity'] . "</th>";
            echo "<th>" . $stock_in['uom'] . "</th>";
            echo "<th>" . $stock_in['invoicenumber'] . "</th>";
            echo "<th>" . $stock_in['shipid'] . "</th>";
            echo "<th>" . $stock_in['mawb'] . "</th>";
            echo "<th>" . $stock_in['hawb'] . "</th>";
            echo "<th>" . $stock_in['receiveddate'] . "</th>";
            echo "<th>" . $stock_in['shipfrom'] . "</th>";
            echo "<th>" . $stock_in['boxno'] . "</th>";
            echo "<th>" . $stock_in['rma'] . "</th>";
            echo "<th>" . $stock_in['warehouse_name'] . "</th>";
            echo "<th>" . $stock_in['rackno'] . "</th>";
            echo "<th>" . $stock_in['docketnumber'] . "</th>";
            echo "<th>" . $stock_in['manufacturingdate'] . "</th>";
            echo "<th>" . $stock_in['pickuprequestdate'] . "</th>";
            echo "<th>" . $stock_in['employee_id'] . "</th>";
            echo "<th>" . $stock_in['eng_id'] . "</th>";
            echo "<th>" . $stock_in['siteid'] . "</th>";
            echo "<th>" . $stock_in['docketdate'] . "</th>";
            echo "<th>" . $stock_in['remarks'] . "</th>";
            echo "<th>" . $stock_in['userid'] . "</th>";
            echo "<th>" . $stock_in['cus_id'] . "</th>";
            echo "<th>" . $stock_in['inserteddate'] . "</th>";
            echo "</tr>";
            foreach ($rows as $row) {
                echo "<tr>";
                echo "<td>";
                echo "<a class='btn btn-danger btn-mini' href='javascript:void(0)' onclick='deletestockin(" . $row["stockin_id"] . ")'>" . $optionsIcons['delete'] . "</a>";
                echo "&nbsp;";
                echo "<a class='btn btn-success btn-mini' href='javascript:void(0)' onclick='savestockin(" . $row["stockin_id"] . ")'>" . $optionsIcons['save'] . "</a>";
                echo "</td>";
                echo "<td>" . $row['serialno'] . "</td>";
                echo "<td>";
                echo getName('projects', 'projectname', 'project_id', $row['project_id'], $db);
                echo "<br/>";
                $idofcustomer = getName('projects', 'cus_id', 'project_id', $row['project_id'], $db);
                $customerid = getName('customerinfo', 'cus_id', 'cus_id', $idofcustomer, $db);
                echo "</td>";
                echo "<td>" . $row['productid'] . "</td>";
                echo "<td>" . $row['description'] . "</td>";
                echo "<td>" . $row['revisionstate'] . "</td>";
                echo "<td>" . getName('shiptype', 'typename', 'shiptype_id', $row['shiptype'], $db) . "</td>";
                echo "<td>" . $row['in_quantity'] . "</td>";
                echo "<td>" . getName('uom', 'measurement', 'uom_id', $row['uom'], $db) . "</td>";
                echo "<td>" . $row['invoicenumber'] . "</td>";
                echo "<td>" . $row['shipid'] . "</td>";
                echo "<td>" . $row['mawb'] . "</td>";
                echo "<td>" . $row['hawb'] . "</td>";
                echo "<td>" . $row['receiveddate'] . "</td>";
                echo "<td>" . $row['shipfrom'] . "</td>";
                echo "<td>" . $row['boxno'] . "</td>";
                echo "<td>" . $row['rma'] . "</td>";
                echo "<td>" . getName('warehouses', 'warehousename', 'warehouse_id', $row['warehouse_id'], $db) . "</td>";
                echo "<td>" . $row['rackno'] . "</td>";
                echo "<td>" . $row['docketnumber'] . "</td>";
                echo "<td>" . $row['manufacturingdate'] . "</td>";
                echo "<td>" . $row['pickuprequestdate'] . "</td>";
                echo "<td>" . getName('employee', 'employeename', 'employee_id', $row['employee_id'], $db) . "</td>";
                echo "<td>" . getName('engineerinfo', 'engname', 'eng_id', $row['eng_id'], $db) . "</td>";
                echo "<td>" . $row['siteid'] . "</td>";
                echo "<td>" . $row['docketdate'] . "</td>";
                echo "<td>" . $row['remarks'] . "</td>";
                echo "<td>" . getName('wms_users', 'username', 'id', $row['userid'], $db) . "</td>";
                echo "<td>" . getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) . "</td>";
                echo "<td>" . $row['inserteddate'] . "</td>";
                echo "</tr>";
            }
            echo "<table>";
        }
    }
}
if (isset($_POST['response_type_id'])) {
    if ($_REQUEST['action'] == 'AddStockOut') {

        $query1 = "INSERT INTO stockout ( stockin_id, serialno, productid, boxno, description, eng_id, response_type_id, revisionstate, challannumber, out_quantity, uom, requestnumber, requestedby, siteid, project_id, requesttime, deliverytime, receivedtime, sla, receivername, cellnumber, warehouseid, transportername, employee_id, remarks, userid, cus_id, session_id, junkentry, inserteddate )
             VALUES ( :stockin_id, :serialno, :productid, :boxno, :description, :eng_id, :response_type_id, :revisionstate, :challannumber, :out_quantity, :uom, :requestnumber, :requestedby, :siteid, :project_id, :requesttime, :deliverytime, :receivedtime, :sla, :receivername, :cellnumber, :warehouse_id, :transportername, :employee_id, :remarks, :userid, :cus_id, :session_id, :junkentry, :inserteddate)";
        $query_params1 = array(
            ':stockin_id' => $_POST['stockin_id'],
            ':serialno' => $_POST['serialno'],
            ':productid' => $_POST['productid'],
            ':boxno' => $_POST['boxno'],
            ':description' => $_POST['description'],
            ':response_type_id' => $_POST['response_type_id'],
            ':eng_id' => $_POST['eng_id'],
            ':revisionstate' => $_POST['revisionstate'],
            ':challannumber' => $_POST['challannumber'],
            ':out_quantity' => $_POST['out_quantity'],
            ':uom' => $_POST['uom'],
            ':requestnumber' => $_POST['requestnumber'],
            ':requestedby' => $_POST['requestedby'],
            ':siteid' => $_POST['siteid'],
            ':project_id' => $_POST['project_id'],
            ':requesttime' => $_POST['requesttime'],
            ':deliverytime' => $_POST['deliverytime'],
            ':receivedtime' => $_POST['receivedtime'],
            ':sla' => $_POST['sla'],
            ':receivername' => $_POST['receivername'],
            ':cellnumber' => $_POST['cellnumber'],
            ':warehouse_id' => $_POST['warehouse_id'],
            ':transportername' => $_POST['transportername'],
            ':employee_id' => $_POST['employee_id'],
            ':remarks' => $_POST['remarks'],
            ':userid' => $_POST['userid'],
            ':cus_id' => $_POST['cus_id'],
            ':session_id' => $_POST['session_id'],
            ':junkentry' => $_POST['junkentry'],
            ':inserteddate' => date('Y-m-d H:i:s')
        );

        try {
            $stmt = $db->prepare($query1);
            $result1 = $stmt->execute($query_params1);
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }

        if ($result1) {
            $session_id = session_id();
            $sess_cusID = $_SESSION['user']['cus_id'];

            $rows = selectAllWhereAA('stockout', 'session_id', $session_id, $db);
            //$rows = selectAllWhereWithDateDifference('stockout', $limit, 'cus_id', $sess_cusID, $db);
            //var_dump($rows);
            echo "<table class=\"form-inline row-fluid table table-striped table-bordered\">";
            echo "<tr>";
            echo "<th>" . $optionsIcons['option'] . "</th>";
            echo "<th>" . $stock_out['serialno'] . "</th>";
            echo "<th>" . $stock_out['productid'] . "</th>";
            echo "<th>" . $stock_out['boxno'] . "</th>";
            echo "<th>" . $stock_out['description'] . "</th>";
            echo "<th>" . $stock_out['eng_id'] . "</th>";
            echo "<th>" . $stock_out['responsetype'] . "</th>";
            echo "<th>" . $stock_out['revisionstate'] . "</th>";
            echo "<th>" . $stock_out['challannumber'] . "</th>";
            echo "<th>" . $stock_out['out_quantity'] . "</th>";
            echo "<th>" . $stock_out['uom'] . "</th>";
            echo "<th>" . $stock_out['requestnumber'] . "</th>";
            echo "<th>" . $stock_out['requestedby'] . "</th>";
            echo "<th>" . $stock_out['siteid'] . "</th>";
            echo "<th>" . $stock_out['project_id'] . "</th>";
            echo "<th>" . $stock_out['requesttime'] . "</th>";
            echo "<th>" . $stock_out['deliverytime'] . "</th>";
            echo "<th>" . $stock_out['receivedtime'] . "</th>";
            echo "<th>" . $stock_out['sla'] . "</th>";
            echo "<th>" . $stock_out['receivername'] . "</th>";
            echo "<th>" . $stock_out['cellnumber'] . "</th>";
            echo "<th>" . $stock_out['warehouseid'] . "</th>";
            echo "<th>" . $stock_out['transportername'] . "</th>";
            echo "<th>" . $stock_out['employee_id'] . "</th>";
            echo "<th>" . $stock_out['remarks'] . "</th>";
            echo "<th>" . $stock_out['user_id'] . "</th>";
            echo "<th>" . $stock_out['cus_id'] . "</th>";
            echo "<th>" . $stock_out['inserteddate'] . "</th>";
            echo "</tr>";
            foreach ($rows as $row) {
                echo "<tr>";
                echo "<td>";
                echo "<a class='btn btn-danger btn-mini' href='javascript:void(0)' onclick='deletestockout(" . $row["stockout_id"] . ")'>" . $optionsIcons['delete'] . "</a>";
                echo "&nbsp;";
                echo "<a class='btn btn-success btn-mini' href='javascript:void(0)' onclick='savestockout(" . $row["stockout_id"] . ")'>" . $optionsIcons['save'] . "</a>";
                echo "</td>";
                echo "<td>" . $row['serialno'] . "</td>";
                echo "<td>" . $row['productid'] . "</td>";
                echo "<td>" . $row['boxno'] . "</td>";
                echo "<td>" . $row['description'] . "</td>";
                echo "<td>" . getName('engineerinfo', 'engname', 'eng_id', $row['eng_id'], $db) . "</td>";
                echo "<td>" . getName('responsetype', 'uniquename', 'responsetype_id', $row['response_type_id'], $db) . "</td>";
                echo "<td>" . $row['revisionstate'] . "</td>";
                echo "<td>" . $row['challannumber'] . "</td>";
                echo "<td>" . $row['out_quantity'] . "</td>";
                echo "<td>" . getName('uom', 'measurement', 'uom_id', $row['uom'], $db) . "</td>";
                echo "<td>" . $row['requestnumber'] . "</td>";
                echo "<td>" . $row['requestedby'] . "</td>";
                echo "<td>" . $row['siteid'] . "</td>";
                echo "<td>" . getName('projects', 'projectname', 'project_id', $row['project_id'], $db) . "</td>";
                echo "<td>" . $row['requesttime'] . "</td>";
                echo "<td>" . $row['deliverytime'] . "</td>";
                echo "<td>" . $row['receivedtime'] . "</td>";
                echo "<td>" . $row['sla'] . "</td>";
                echo "<td>" . $row['receivername'] . "</td>";
                echo "<td>" . $row['cellnumber'] . "</td>";
                echo "<td>" . getName('warehouses', 'warehousename', 'warehouse_id', $row['warehouseid'], $db) . "</td>";
                echo "<td>" . $row['transportername'] . "</td>";
                echo "<td>" . getName('employee', 'employeename', 'employee_id', $row['employee_id'], $db) . "</td>";
                echo "<td>" . $row['remarks'] . "</td>";
                echo "<td>" . getName('wms_users', 'username', 'id', $row['userid'], $db) . "</td>";
                echo "<td>" . getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) . "</td>";
                echo "<td>" . $row['inserteddate'] . "</td>";
                echo "</tr>";
            }
            echo "<table>";
        }
    }
}

// Add Returns of Faulty
if (isset($_POST['serialno'])) {
    if ($_REQUEST['action'] == 'AddFaulty') {
        $query = "INSERT INTO faulties ( serialno, project_id, rma, pickuprequestdate, physicallyreceivedate, productid, description, 
            revisionstate, boxno, return_quantity, uom, manufacturingdate, faultiesstatus, siteid, warehouseid, employeeid, receivedfrom, 
            docketdate, faulties_docketnumber, remarks, userid, cus_id, session_id, junkentry, inserteddate )
             
            VALUES ( :serialno, :project_id, :rma, :pickuprequestdate, :physicallyreceivedate, :productid, :description, :revisionstate, 
            :boxno, :return_quantity, :uom, :manufacturingdate, :faultiesstatus, :siteid, :warehouseid, :employeeid, :receivedfrom, 
            :docketdate, :faulties_docketnumber, :remarks, :userid, :cus_id, :session_id, :junkentry, :inserteddate)";

        $query_params = array(
            ':serialno' => $_POST['serialno'],
            ':project_id' => $_POST['project_id'],
            ':rma' => $_POST['rma'],
            ':pickuprequestdate' => $_POST['pickuprequestdate'],
            ':physicallyreceivedate' => $_POST['physicallyreceivedate'],
            ':productid' => $_POST['productid'],
            ':description' => $_POST['description'],
            ':revisionstate' => $_POST['revisionstate'],
            ':boxno' => $_POST['boxno'],
            ':uom' => $_POST['uom'],
            ':return_quantity' => $_POST['return_quantity'],
            ':manufacturingdate' => $_POST['manufacturingdate'],
            ':faultiesstatus' => $_POST['faultiesstatus'],
            ':siteid' => $_POST['siteid'],
            ':warehouseid' => $_POST['warehouseid'],
            ':employeeid' => $_POST['employeeid'],
            ':receivedfrom' => $_POST['receivedfrom'],
            ':docketdate' => $_POST['docketdate'],
            ':faulties_docketnumber' => $_POST['faulties_docketnumber'],
            ':remarks' => $_POST['remarks'],
            ':userid' => $_POST['userid'],
            ':cus_id' => $_POST['cus_id'],
            ':session_id' => $_POST['session_id'],
            ':junkentry' => $_POST['junkentry'],
            ':inserteddate' => date('Y-m-d H:i:s')
        );
        //var_dump($query_params);
        try {
            $stmt = $db->prepare($query);
            $result = $stmt->execute($query_params);
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }

        if ($result) {
            $session_id = session_id();
            $rows = selectAllWhereAA('faulties', 'session_id', $session_id, $db);
            //var_dump($rows);
            echo "<table class=\"row-fluid table table-striped table-bordered\">";
            echo "<tr>";
            echo "<th>" . $optionsIcons['optionIcon'] . "</th>";
            echo "<th>" . $faulties['serialno'] . "</th>";
            echo "<th>" . $faulties['project_id'] . "</th>";
            echo "<th>" . $faulties['rma'] . "</th>";
            echo "<th>" . $faulties['pickuprequestdate'] . "</th>";
            echo "<th>" . $faulties['physicallyreceivedate'] . "</th>";
            echo "<th>" . $faulties['productid'] . "</th>";
            echo "<th>" . $faulties['description'] . "</th>";
            echo "<th>" . $faulties['revisionstate'] . "</th>";
            echo "<th>" . $faulties['boxno'] . "</th>";
            echo "<th>" . $faulties['uom'] . "</th>";
            echo "<th>" . $faulties['return_quantity'] . "</th>";
            echo "<th>" . $faulties['manufacturingdate'] . "</th>";
            echo "<th>" . $faulties['faultiesstatus'] . "</th>";
            echo "<th>" . $faulties['siteid'] . "</th>";
            echo "<th>" . $faulties['warehouseid'] . "</th>";
            echo "<th>" . $faulties['employeeid'] . "</th>";
            echo "<th>" . $faulties['docketdate'] . "</th>";
            echo "<th>" . $faulties['faulties_docketnumber'] . "</th>";
            echo "<th>" . $faulties['remarks'] . "</th>";
            echo "<th>" . $faulties['userid'] . "</th>";
            echo "<th>" . $customer_info['cusname'] . "</th>";
            echo "<th>" . $faulties['inserteddate'] . "</th>";
            echo "</tr>";
            foreach ($rows as $row) {
                echo "<tr>";
                echo "<td>";
                echo "<a class='btn btn-danger btn-mini' href='javascript:void(0)' onclick='deletereturn(" . $row["faulties_id"] . ")'>" . $optionsIcons['delete'] . "</a>";
                echo "&nbsp;";
                echo "<a class='btn btn-success btn-mini' href='javascript:void(0)' onclick='savereturn(" . $row["faulties_id"] . ")'>" . $optionsIcons['save'] . "</a>";
                echo "</td>";
                echo "<td>" . $row['serialno'] . "</td>";
                echo "<td>";
                echo getName('projects', 'projectname', 'project_id', $row['project_id'], $db);
                echo "<br/>";
                $idofcustomer = getName('projects', 'cus_id', 'project_id', $row['project_id'], $db);
                $customerid = getName('customerinfo', 'cus_id', 'cus_id', $idofcustomer, $db);
                echo "</td>";
                echo "<td>" . $row['rma'] . "</td>";
                echo "<td>" . $row['pickuprequestdate'] . "</td>";
                echo "<td>" . $row['physicallyreceivedate'] . "</td>";
                echo "<td>" . $row['productid'] . "</td>";
                echo "<td>" . $row['description'] . "</td>";
                echo "<td>" . $row['revisionstate'] . "</td>";
                echo "<td>" . $row['boxno'] . "</td>";
                echo "<td>" . getName('uom', 'measurement', 'uom_id', $row['uom'], $db) . "</td>";
                echo "<td>" . $row['return_quantity'] . "</td>";
                echo "<td>" . $row['manufacturingdate'] . "</td>";
                echo "<td>" . getName('faultystatus', 'statusname', 'status_id', $row['faultiesstatus'], $db) . "</td>";
                echo "<td>" . $row['siteid'] . "</td>";
                echo "<td>" . getName('warehouses', 'warehousename', 'warehouse_id', $row['warehouseid'], $db) . "</td>";
                echo "<td>" . getName('employee', 'employeename', 'employee_id', $row['employeeid'], $db) . "</td>";
                echo "<td>" . $row['docketdate'] . "</td>";
                echo "<td>" . $row['faulties_docketnumber'] . "</td>";
                echo "<td>" . $row['remarks'] . "</td>";
                echo "<td>" . getName('wms_users', 'username', 'id', $row['userid'], $db) . "</td>";
                echo "<td>" . getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) . "</td>";
                echo "<td>" . $row['inserteddate'] . "</td>";
                echo "</tr>";
            }
            echo "<table>";
        }
    }
}
// Add Faulty Export
if (isset($_POST['serialno'])) {
    if ($_REQUEST['action'] == 'AddExport') {
        $query = "INSERT INTO faulty_export (serialno, project_id, productid, description, revisionstate, boxno, 
                uom, faulty_export_quantity, handedoverto, manufacturingdate, faultydocketnumber, docketdate, siteid, 
                warehouse_id, rr_rma, export_rma, rr_invoiceno, rr_date, rr_mawb, rr_awb, remarks, userid, 
                cus_id, session_id, junkentry, inserteddate)
             
            VALUES (:serialno, :project_id, :productid, :description, :revisionstate, :boxno, :uom, :faulty_export_quantity, 
            :handedoverto, :manufacturingdate, :faultydocketnumber, :docketdate, :siteid, :warehouse_id, :rr_rma, :export_rma, 
            :rr_invoiceno, :rr_date, :rr_mawb, :rr_awb, :remarks, :userid, :cus_id, :session_id, :junkentry, :inserteddate)";

        $query_params = array(
            ':serialno' => $_POST['serialno'],
            ':project_id' => $_POST['project_id'],
            ':productid' => $_POST['productid'],
            ':description' => $_POST['description'],
            ':revisionstate' => $_POST['revisionstate'],
            ':boxno' => $_POST['boxno'],
            ':uom' => $_POST['uom'],
            ':faulty_export_quantity' => $_POST['faulty_export_quantity'],
            ':handedoverto' => $_POST['handedoverto'],
            ':manufacturingdate' => $_POST['manufacturingdate'],
            ':faultydocketnumber' => $_POST['faultydocketnumber'],
            ':docketdate' => $_POST['docketdate'],
            ':siteid' => $_POST['siteid'],
            ':warehouse_id' => $_POST['warehouse_id'],
            ':rr_rma' => $_POST['rr_rma'],
            ':export_rma' => $_POST['export_rma'],
            ':rr_invoiceno' => $_POST['rr_invoiceno'],
            ':rr_date' => $_POST['rr_date'],
            ':rr_mawb' => $_POST['rr_mawb'],
            ':rr_awb' => $_POST['rr_awb'],
            ':remarks' => $_POST['remarks'],
            ':userid' => $_POST['userid'],
            ':cus_id' => $_POST['cus_id'],
            ':session_id' => $_POST['session_id'],
            ':junkentry' => $_POST['junkentry'],
            ':inserteddate' => date('Y-m-d H:i:s')
        );

        try {
            $stmt = $db->prepare($query);
            $result = $stmt->execute($query_params);
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }

        $session_id = session_id();
        $rows = selectAllWhereAA('faulty_export', 'session_id', $session_id, $db);

        echo "<table class=\"row-fluid table table-striped table-bordered\">";
        echo "<tr>";
        echo "<th>" . $optionsIcons['optionIcon'] . "</th>";
        echo "<th>" . $faulty_export['serialno'] . "</th>";
        echo "<th>" . $faulty_export['project_id'] . "</th>";
        echo "<th>" . $faulty_export['productid'] . "</th>";
        echo "<th>" . $faulty_export['description'] . "</th>";
        echo "<th>" . $faulty_export['revisionstate'] . "</th>";
        echo "<th>" . $faulty_export['boxno'] . "</th>";
        echo "<th>" . $faulty_export['uom'] . "</th>";
        echo "<th>" . $faulty_export['faulty_export_quantity'] . "</th>";
        echo "<th>" . $faulty_export['handedoverto'] . "</th>";
        echo "<th>" . $faulty_export['manufacturingdate'] . "</th>";
        echo "<th>" . $faulty_export['faultydocketnumber'] . "</th>";
        echo "<th>" . $faulty_export['docketdate'] . "</th>";
        echo "<th>" . $faulty_export['siteid'] . "</th>";
        echo "<th>" . $faulty_export['warehouse_id'] . "</th>";
        echo "<th>" . $faulty_export['rr_rma'] . "</th>";
        echo "<th>" . $faulty_export['export_rma'] . "</th>";
        echo "<th>" . $faulty_export['rr_invoiceno'] . "</th>";
        echo "<th>" . $faulty_export['rr_date'] . "</th>";
        echo "<th>" . $faulty_export['rr_mawb'] . "</th>";
        echo "<th>" . $faulty_export['rr_awb'] . "</th>";
        echo "<th>" . $faulty_export['remarks'] . "</th>";
        echo "<th>" . $faulty_export['userid'] . "</th>";
        echo "<th>" . $customer_info['cusname'] . "</th>";
        echo "<th>" . $faulty_export['inserteddate'] . "</th>";
        echo "</tr>";
        foreach ($rows as $row) {
            echo "<tr>";
            echo "<td>";
            echo "<a class='btn btn-danger btn-mini' href='javascript:void(0)' onclick='deleteexport(" . $row["faulty_export_id"] . ")'>" . $optionsIcons['delete'] . "</a>";
            echo "&nbsp;";
            echo "<a class='btn btn-success btn-mini' href='javascript:void(0)' onclick='saverexport(" . $row["faulty_export_id"] . ")'>" . $optionsIcons['save'] . "</a>";
            echo "</td>";
            echo "<td>" . $row['serialno'] . "</td>";
            echo "<td>";
            echo getName('projects', 'projectname', 'project_id', $row['project_id'], $db);
            echo "<br/>";
            $idofcustomer = getName('projects', 'cus_id', 'project_id', $row['project_id'], $db);
            $customerid = getName('customerinfo', 'cus_id', 'cus_id', $idofcustomer, $db);
            echo "</td>";
            echo "<td>" . $row['productid'] . "</td>";
            echo "<td>" . $row['description'] . "</td>";
            echo "<td>" . $row['revisionstate'] . "</td>";
            echo "<td>" . $row['boxno'] . "</td>";
            echo "<td>" . getName('uom', 'measurement', 'uom_id', $row['uom'], $db) . "</td>";
            echo "<td>" . $row['faulty_export_quantity'] . "</td>";
            echo "<td>" . $row['handedoverto'] . "</td>";
            echo "<td>" . $row['manufacturingdate'] . "</td>";
            echo "<td>" . $row['faultydocketnumber'] . "</td>";
            echo "<td>" . $row['docketdate'] . "</td>";
            echo "<td>" . $row['siteid'] . "</td>";
            echo "<td>" . getName('warehouses', 'warehousename', 'warehouse_id', $row['warehouse_id'], $db) . "</td>";
            echo "<td>" . $row['rr_rma'] . "</td>";
            echo "<td>" . $row['export_rma'] . "</td>";
            echo "<td>" . $row['rr_invoiceno'] . "</td>";
            echo "<td>" . $row['rr_date'] . "</td>";
            echo "<td>" . $row['rr_mawb'] . "</td>";
            echo "<td>" . $row['rr_awb'] . "</td>";
            echo "<td>" . $row['remarks'] . "</td>";
            echo "<td>" . getName('wms_users', 'username', 'id', $row['userid'], $db) . "</td>";
            echo "<td>" . getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) . "</td>";
            echo '<input type="hidden" name="session_id" value="' . session_id() . '" />';
            echo '<input type="hidden" name="junkentry" value="0" />';
            echo "<td>" . $row['inserteddate'] . "</td>";
            echo "</tr>";
        }
        echo "<table>";
    }
}
?>